package com.mmy.study.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 设置跨域
 */
@Configuration
public class WebCrosConfig implements WebMvcConfigurer {
    private static final long MAX_AGE = 24 * 60 * 60; // 24小时
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS")
                .maxAge(MAX_AGE)
                .exposedHeaders("*")
                .allowedHeaders("*");
    }
}
